package model

import (
	"smart-health-platforms/config"
	"time"
	"user_srv/user"
)

type MembershipLevels struct {
	Id          int32     `gorm:"column:id;type:int;primaryKey;not null;" json:"id"`
	Name        string    `gorm:"column:name;type:varchar(255);comment:会员名称;not null;" json:"name"`    // 会员名称
	Grade       int32     `gorm:"column:grade;type:int;comment:会员等级;not null;default:0;" json:"grade"` // 会员等级
	Description string    `gorm:"column:description;type:text;comment:等级描述;" json:"description"`       // 等级描述
	CreatedAt   time.Time `gorm:"column:created_at;type:datetime(3);default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt   time.Time `gorm:"column:updated_at;type:datetime(3);default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt   time.Time `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (m *MembershipLevels) TableName() string {
	return "membership_levels"
}

// CreateMembershipLevel 创建会员等级
func (m *MembershipLevels) CreateMembershipLevel() error {
	return config.DB.Create(&m).Error
}

// GetMembershipLevel 获取会员等级
func (m *MembershipLevels) GetMembershipLevel() (list []*user.MembershipLevelList, err error) {
	err = config.DB.Model(&MembershipLevels{}).Find(&list).Error
	return
}

// UpdateMembershipLevel 更新会员等级
func (m *MembershipLevels) UpdateMembershipLevel() error {
	return config.DB.Updates(&m).Error
}

// DeleteMembershipLevel 删除会员等级
func (m *MembershipLevels) DeleteMembershipLevel() error {
	return config.DB.Delete(&m).Error
}
